﻿@model IEnumerable<LanDBom.Models.LanJiLu>
@using LanDBom.Resources
@{
    ViewBag.Title = "Index";
}

<h2>@Resource.String425</h2>
<form class="row padtop col-12" action="/LanJiLus/Index" method="post">
    <fieldset class="boun">
        <legend class="len">查询条件</legend>
        <div class="row">
            <div class="col-3">@Html.Label(Resource.String426)</div>
            <div class="col-3">@Html.TextBox("ming", "", new { @class = "input-au" })</div>
            <div class="col-3">
                <input type="submit" value="查询" name="cha" class="col-3" />
            </div>
        </div>
    </fieldset>
</form>

<div id="WT_dh_mb2" style="z-index:10000;display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
    <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
        <div id="WJ_XZLJ"></div>
    </div>
    <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
</div>

<div id="WT_dh_mb3" style="display: none; position: absolute; border: 1px black solid; left: 15%; top: 25%; background-color: white; background-color: #f1f1f1;height:500px;width:800px">
    <div style="text-align: right; background-color: #84acde;" class="Tuodong"><span class="WT_qxbh3" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff;" class="row" >
        <div class="col-4">
            <div >
                <input type="button" placeholder="选择物料类型" id="xuanzhe" value="选择物料类型" />
            </div>
            <div style="display:none;position:absolute;background-color:white" id="beixh">
                <ul style="padding: 5px; width: 150px; list-style-type:none">
                    <li><input name="leix2" id="mycbk" type="checkbox" value="全部" />全部</li>
                    <li><input name="leix" class="mycbk" type="checkbox" value="纸质" />纸质</li>
                    <li><input name="leix" class="mycbk" type="checkbox" value="木质" />木质</li>
                    <li><input name="leix" class="mycbk" type="checkbox" value="塑料" />塑料</li>
                    <li><input name="leix" class="mycbk" type="checkbox" value="辅料" />辅料</li>
                    <li><input name="leix" class="mycbk" type="checkbox" value="辅料" />辅料</li>
                    <li><input name="leix" class="mycbk" type="checkbox" value="金属" />金属</li>
                </ul>
                <div><button id="qued">确定</button>&emsp;&emsp;&emsp;&emsp;&emsp;<button id="quxiaio">取消</button></div>
            </div>
        </div>
        <div class="col-6">
            <button id="jian"><<<</button>
            <input type="text" id="year"/>
            <button id="jia">>>></button>
        </div>
        <div class="col-2">
            <button id="xilaexcel">下载报表</button>
        </div>
    </div>

    <div style="width:100%;height:300px;overflow:auto">
        <table style="width:100%">
            <thead>
                <tr>
                    <th style="width:8%">物料名</th>
                    <th style="width:7%">物料类型</th>
                    <th style="width:7%">一月</th>
                    <th style="width:7%">二月</th>
                    <th style="width:7%">三月</th>
                    <th style="width:7%">四月</th>
                    <th style="width:7%">五月</th>
                    <th style="width:7%">六月</th>
                    <th style="width:7%">七月</th>
                    <th style="width:7%">八月</th>
                    <th style="width:7%">九月</th>
                    <th style="width:7%">十月</th>
                    <th style="width:7%">十一月</th>
                    <th style="width:7%">十二月</th>
                </tr>
            </thead>
            <tbody id="table_tb1">
            </tbody>
        </table>
    </div>
    <div style="text-align:center"><button class="WT_qxbh3">@Resource.String126</button></div>
</div>
<p>
    @*<button id="dhk">查看表报</button>*@
</p>
<table class="tab table">
    <thead class="thead-light">
        <tr style="text-align-last:center;">
            <th>
                @Html.Label(Resource.String426)
            </th>
            <th>
                @Html.Label(Resource.String427)
            </th>
            <th>
                @Html.Label(Resource.String422)
            </th>
            <th>
                @Html.Label(Resource.String423)
            </th>
        </tr>
    </thead>
    <tbody style="height:450px" class="gun" id="BUtain">
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.JL_Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.JL_Fen)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.JL_Time)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.JL_Price)
                </td>
            </tr>
        }
    </tbody>


</table>
@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $("#li13").css({ "color": "black", "background-color": "white" })
        $(function () {
            var now = new Date($.now());
            var year = (now.getFullYear()).toString();
            $("#year").val(year)
            $(document).on("click", "#jian", function () {
                var y = $("#year").val()*1
                $("#year").val(y - 1)
                biaobxx()
            })
            $(document).on("click", "#jia", function () {
                var y = $("#year").val() * 1
                $("#year").val(y + 1)
                biaobxx()
            })



            $(document).on("click", "#dhk", function () {
                $("#WT_dh_mb3").css({ "display": "block" })
            })
            $(document).on("click", ".WT_qxbh3", function () {
                $("#WT_dh_mb3").css({ "display": "none" })
            })

            $(document).on("click", "#xuanzhe", function () {
                $("#beixh").css({"display":"block"})
            })
            $(document).on("click", "#quxiaio", function () {
                $("#beixh").css({ "display": "none" })
                $('.mycbk').prop('checked', false);

            })

            $(document).on("click", "#qued", function () {
                biaobxx()
                
            })

            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })

            $(document).on("click", "#mycbk", function () {

                if ($("#mycbk").prop("checked") == true) {
                    $('.mycbk').prop('checked', true); 
                }
                else {
                    $('.mycbk').prop('checked', false); 
                }

            })
            $(document).on("click", "#xilaexcel", function () {
                var CG_XX = [];
                var check = $("input[name=leix]:checked").length;
                if (check == 0) {
                    alert("至少选中一种！")
                }
                else {
                    $("input[name=leix]:checked").each(function (i, item) {

                        CG_XX.push({
                            AP_bian: $(item).val()
                        })
                        console.log("共" + CG_XX.length + "数据");
                        console.log(CG_XX);
                    })
                    var year = $("#year").val()
                    $.ajax({
                        url: "/LanJiLus/DownloadExcel",
                        type: 'POST',
                        data: { "Designdraws": CG_XX, "state": 1, "year": year },
                        success: function (text) {

                            $("#WT_dh_mb2").css({ "display": "block" })
                            $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                        },
                        error: function (text) {
                            alert("系统错误");
                        }
                    })

                }
            })

            function biaobxx() {
                var CG_XX = [];
                var check = $("input[name=leix]:checked").length;
                if (check == 0) {
                    alert("至少选中一种！")
                }
                else {
                    $("input[name=leix]:checked").each(function (i, item) {

                        CG_XX.push({
                            AP_bian: $(item).val()
                        })
                        console.log("共" + CG_XX.length + "数据");
                        console.log(CG_XX);
                    })
                    var year = $("#year").val()
                    $.ajax({
                        url: "/LanJiLus/DownloadExce2",
                        type: 'POST',
                        data: { "Designdraws": CG_XX, "state": 1, "year": year },
                        success: function (text) {
                            $("#beixh").css({ "display": "none" })
                            daying(text)
                        },
                        error: function (text) {
                            alert("系统错误");
                        }
                    })

                }
            }

            function daying(sjik) {
                $("#table_tb1 tr").remove();
                $.each(sjik, function (i, item) {
                    var $tr = (`
                         <tr style="height:20px">
                             <td style="width:8%">${item.name}</td>
                             <td style="width:7%" >${item.lei}</td>
                             <td style="width:7%">${item.a}</td>
                             <td style="width:7%">${item.b}</td>
                             <td style="width:7%">${item.c}</td>
                             <td style="width:7%">${item.d}</td>
                             <td style="width:7%">${item.e}</td>
                             <td style="width:7%">${item.f}</td>
                             <td style="width:7%">${item.g}</td>
                             <td style="width:7%">${item.h}</td>
                             <td style="width:7%">${item.i}</td>
                             <td style="width:7%">${item.j}</td>
                             <td style="width:7%">${item.k}</td>
                             <td style="width:7%">${item.l}</td>
                         </tr>`);
                    $("#table_tb1").append($tr);
                })
            }
        })
    </script>
}